package com.xczz.common.result;

import com.xczz.common.constant.HttpStatus;
import com.xczz.utils.StringUtils;

import java.util.HashMap;

public class RestResult extends HashMap<String,Object> {
    private static final long serialVersionUID=1L;
    public static final String CODE_TAG="code";
    public static final String MSG_TAG="msg";
    public static final String DATA_TAG="data";

    public RestResult(){
    }

    public RestResult(int code,String msg){
        super.put(CODE_TAG,code);
        super.put(MSG_TAG,msg);
    }

    public RestResult(int code,String msg,Object data){
        super.put(CODE_TAG,code);
        super.put(MSG_TAG,msg);
        if(StringUtils.isNotNull(data)){
            super.put(DATA_TAG,data);
        }
    }

    public static RestResult success(){
        return RestResult.success("操作成功");
    }

    public static RestResult success(Object data){
        return RestResult.success("操作成功",data);
    }

    public static RestResult success(String msg){
        return RestResult.success(msg,null);
    }

    public static RestResult success(String msg,Object data){
        return new RestResult(HttpStatus.SUCCESS,msg,data);
    }

    public static RestResult error(){
        return RestResult.error("操作失败");
    }

    public static RestResult error(String msg){
        return RestResult.error(msg,null);
    }

    public static RestResult error(String msg,Object data){
        return new RestResult(HttpStatus.ERROR,msg,data);
    }

    public static RestResult error(int code,String msg){
        return new RestResult(code,msg,null);
    }
}
